//
//  News.m
//  ItApp1
//
//  Created by QUAQUA on 2017/11/8.
//  Copyright © 2017年 zws. All rights reserved.
//

#import "News.h"
#import "NewsCell.h"
#import "YSHYSlideViewController.h"
#import "Header.h"
#import "ZPMessageViewController.h"
#import "ZPTabBarController.h"
#import "ZPNavigationController.h"
#import "ZPHomeViewController.h"//首页
#import "ZPMessageHomeViewController.h"//对话

@interface News ()<UITableViewDelegate,UITableViewDataSource>{
    NSMutableArray *arr1,*arr2,*image,*arr3,*arr4,*arr5;
    UIButton *bianJi;
    //int cellnum;
}

@end

@implementation News

- (void)viewDidLoad {
    [super viewDidLoad];
    UIRefreshControl *refresh = [[UIRefreshControl alloc]init];
    refresh.attributedTitle = [[NSAttributedString alloc]initWithString:@"下拉刷新"];
    [refresh addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
    self.refreshControl = refresh;

    self.tableView.frame=[UIScreen mainScreen].bounds;
    NSLog(@"%f",[UIScreen mainScreen].bounds.size.height);
    self.tableView.tableFooterView=[[UIView alloc]init];
    self.title=@"消息";

  arr1=[[NSMutableArray alloc]initWithObjects:@"aaa",@"ccc",@"ddd",@"eee",@"fff", nil];
    arr2=[[NSMutableArray alloc]initWithObjects:@"ccc",@"ddd",@"aaa",@"ddd",@"sss", nil];
    image=[[NSMutableArray alloc]initWithObjects:@"Gallery - Image - 1",@"Gallery - Image - 2",@"Gallery - Image - 2",@"Gallery - Image - 1",@"Gallery - Image - 2", nil];

    
    [self.tableView registerNib:[UINib nibWithNibName:@"NewsCell" bundle:nil] forCellReuseIdentifier:@"News"];
   // [self.navigationController setNavigationBarHidden:NO];


    self.navigationController.navigationBar.barTintColor=[UIColor whiteColor];
    
////
    UIButton *back=[[UIButton alloc]init];
    UIImage *img=[UIImage imageNamed:@"Chevron"];
    [back setImage:img forState:UIControlStateNormal];
    //    back.frame=CGRectMake(0, 0, 12.5, 21);
    [back addTarget:self action:@selector(toIndexView) forControlEvents:UIControlEventTouchDown];
    UIBarButtonItem *left=[[UIBarButtonItem alloc]initWithCustomView:back];
    self.navigationItem.leftBarButtonItem=left;
   // self.tabBarController.tabBar.hidden=YES;
    self.editing=NO;

    
    self.navigationController.navigationBarHidden=YES;
    [self.navigationController setNavigationBarHidden:NO];


//    self.view.backgroundColor=[UIColor redColor];
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
//-(void)editing{
//     self.editing=YES;
////    [bianJi setTitle:@"取消" forState:UIControlStateNormal];
////    [bianJi addTarget:self action:@selector(quXiao) forControlEvents:UIControlEventTouchDown];
//}
//-(void)quXiao{
//    self.editing=NO;
//}
-(void)toIndexView{
        [[YSHYSlideViewController shareInstance] ppp];
//     [self.navigationController setNavigationBarHidden:YES];
    self.tabBarController.tabBar.hidden=NO;
    [self.navigationController popViewControllerAnimated:YES];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)viewWillAppear:(BOOL)animated{
    
}
- (void)refresh{
    //    if (self.refreshControl.refreshing){
    // [self.modelArray removeAllObjects];//清除旧数据，每次都加载最新的数据
    //self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"加载中..."];
    // [self addData];
    self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"下拉刷新"];
    [self.tableView reloadData];
//    [self AFGetData];
//    [self AFNetMonitor];
    [self.refreshControl endRefreshing];
    
}
#pragma mark - Table view data source
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 65;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return arr1.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    NewsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"News" forIndexPath:indexPath];

    
    cell.name.text=arr1[indexPath.row];
    cell.news.text=arr2[indexPath.row];
    cell.head.image=[UIImage imageNamed:image[indexPath.row]];
    cell.head.layer.masksToBounds=YES;
    cell.head.layer.cornerRadius=cell.head.bounds.size.width/2;
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; //初始化格式器。
    [formatter setDateFormat:@"hh:mm:ss"];//定义时间为这种格式： YYYY-MM-dd hh:mm:ss 。
    NSString *currentTime = [formatter stringFromDate:[NSDate date]];//将NSDate  ＊对象 转化为 NSString ＊对象。
    cell.time.text=currentTime;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    ZPMessageViewController *message = [[ZPMessageViewController alloc] init];
    message.hidesBottomBarWhenPushed = YES;
  
    ZPNavigationController *messageNavi = [[ZPNavigationController alloc] initWithRootViewController:message];
    messageNavi.tabBarItem.title = @"对话";
    [self presentViewController:messageNavi animated:YES completion:nil];
}

@end
